package com.ruihu.admin.module.business.log.aiimagelog.controller;

import com.ruihu.admin.common.domain.PageResultDTO;
import com.ruihu.admin.common.controller.BaseController;
import com.ruihu.admin.common.domain.ResponseDTO;
import com.ruihu.admin.common.domain.ValidateList;
import com.ruihu.admin.module.business.log.aiimagelog.domain.dto.AiImageLogAddDTO;
import com.ruihu.admin.module.business.log.aiimagelog.domain.dto.AiImageLogUpdateDTO;
import com.ruihu.admin.module.business.log.aiimagelog.domain.dto.AiImageLogQueryDTO;
import com.ruihu.admin.module.business.log.aiimagelog.domain.vo.AiImageLogVO;
import com.ruihu.admin.module.business.log.aiimagelog.domain.vo.AiImageLogExcelVO;
import com.ruihu.admin.module.business.log.aiimagelog.service.AiImageLogService;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import org.apache.poi.ss.usermodel.Workbook;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * [  ]
 *
 * @author Tony
 * @version 1.0
 * @company 瑞虎（南京）信息技术有限公司
 * @copyright (c)  瑞虎（南京）信息技术有限公司Inc. All rights reserved.
 * @date 2023-01-30 13:54:39
 * @since JDK1.8
 */
@RestController
@Api(tags = {"AI图片接口日志"})
public class AiImageLogController extends BaseController {

    @Autowired
    private AiImageLogService aiImageLogService;

    @ApiOperation(value = "分页查询",notes = "@author Tony")
    @PostMapping("/aiImageLog/page/query")
    public ResponseDTO<PageResultDTO<AiImageLogVO>> queryByPage(@RequestBody AiImageLogQueryDTO queryDTO) {
        return aiImageLogService.queryByPage(queryDTO);
    }

    @ApiOperation(value = "添加",notes = "@author Tony")
    @PostMapping("/aiImageLog/add")
    public ResponseDTO<String> add(@RequestBody @Validated AiImageLogAddDTO addTO){
        return aiImageLogService.add(addTO);
    }

    @ApiOperation(value="修改",notes = "@author Tony")
    @PostMapping("/aiImageLog/update")
    public ResponseDTO<String> update(@RequestBody @Validated AiImageLogUpdateDTO updateDTO){
        return aiImageLogService.update(updateDTO);
    }

    @ApiOperation(value="批量删除",notes = "@author Tony")
    @PostMapping("/aiImageLog/deleteByIds")
    public ResponseDTO<String> delete(@RequestBody @Validated ValidateList<Long> idList) {
        return aiImageLogService.deleteByIds(idList);
    }

    @ApiOperation(value = "批量导出", notes = "@author Tony")
    @PostMapping("/aiImageLog/export/batch")
    public void batchExport(@RequestBody @Validated ValidateList<Long> idList, HttpServletResponse response) {
        //查询数据
        List<AiImageLogExcelVO> aiImageLogList = aiImageLogService.queryBatchExportData(idList);
        //导出操作
        ExportParams ex = new ExportParams("", "Sheet1");
        Workbook workbook = ExcelExportUtil.exportExcel(ex, AiImageLogExcelVO.class, aiImageLogList);
        downloadExcel("", workbook, response);
    }

    @ApiOperation(value = "导出全部", notes = "@author Tony")
    @PostMapping("/aiImageLog/export/all")
    public void exportAll(@RequestBody @Validated AiImageLogQueryDTO queryDTO, HttpServletResponse response) {
        //查询数据
        List<AiImageLogExcelVO> aiImageLogList = aiImageLogService.queryAllExportData(queryDTO);
        //导出操作
        ExportParams ex = new ExportParams("", "Sheet1");
        Workbook workbook = ExcelExportUtil.exportExcel(ex, AiImageLogExcelVO.class, aiImageLogList);
        downloadExcel("", workbook, response);
    }

}
